//
//  ECUCatalogModel.m
//  Edu_iOS
//
//  Created by apple on 2017/9/23.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUCatalogModel.h"

@implementation ECUCatalogModel

+ (instancetype)modelWithDic:(NSDictionary *)dic {
    ECUCatalogModel *foldCellModel = [ECUCatalogModel new];
    foldCellModel.text = dic[@"text"];
    foldCellModel.belowCount = 0;
    foldCellModel.time = dic[@"time"];
    foldCellModel.type = dic[@"type"];
    
    
    foldCellModel.submodels = [NSMutableArray new];
    NSArray *submodels = dic[@"submodels"];
    for (int i = 0; i < submodels.count; i++) {
        ECUCatalogModel *submodel = [ECUCatalogModel modelWithDic:(NSDictionary *)submodels[i]];
        submodel.supermodel = foldCellModel;
        [foldCellModel.submodels addObject:submodel];
    }
    
    return foldCellModel;
}

- (NSArray *)open {
    NSArray *submodels = self.submodels;
    self.submodels = nil;
    self.belowCount = submodels.count;
    return submodels;
}

- (void)closeWithSubmodels:(NSArray *)submodels {
    self.submodels = [NSMutableArray arrayWithArray:submodels];
    self.belowCount = 0;
}

- (void)setBelowCount:(NSInteger)belowCount {
    self.supermodel.belowCount += (belowCount - _belowCount);
    _belowCount = belowCount;
}

@end

@implementation ECDetailOfListModel

+(NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"ID":@"id"};
}

@end

@implementation ECListModel

+ (NSArray *)mj_ignoredPropertyNames{
    return @[@"level",@"isLearning"];
}

@end

